#include"../LibDGGSBase/DGGSDefine.hpp"
using namespace NNU::DGGS::Base;


/// <summary>
/// 生成全球格网的参数结构体
/// </summary>
struct GlobalGridParams
{
    std::string outFileName;
    int level=0;
    DGGSElementType elementType=DGGSElementType::Unknown;
    DGGSGridType gridType=DGGSGridType::Unknown;
    bool isValid()
    {
        if(outFileName.empty()||elementType==DGGSElementType::Unknown||gridType==DGGSGridType::Unknown||level==0)
            return false;
        else
            return true;
    }
};

/// <summary>
/// 生成局部格网的参数结构体
/// </summary>
struct PartitialGridParams
{
    std::string inFileName;
    std::string outFileName;
    int level=0;
    DGGSElementType elementType=DGGSElementType::Unknown;
    DGGSGridType gridType=DGGSGridType::Unknown;
    bool isValid()
    {
        if(inFileName.empty()||outFileName.empty()||elementType==DGGSElementType::Unknown||gridType==DGGSGridType::Unknown||level==0)
            return false;
        else
            return true;
    }
};

/// <summary>
/// 矢量转格网的参数结构体
/// </summary>
struct Ogr2DGGSParams
{
    std::string inFileName;
    std::string outFileName;
    int level=0;
    DGGSElementType elementType=DGGSElementType::Unknown;
    DGGSGridType gridType=DGGSGridType::Unknown;
    bool isValid()
    {
        if(inFileName.empty()||outFileName.empty()||elementType==DGGSElementType::Unknown||gridType==DGGSGridType::Unknown||level==0)
            return false;
        else
            return true;
    }
};

/// <summary>
/// 格网转矢量参数结构体
/// </summary>
struct DGGS2OgrParams
{
    std::string inFileName;
    std::string outFileName;
    bool isValid()
    {
        if(inFileName.empty()||outFileName.empty())
            return false;
        else
            return true;
    }
};

/// <summary>
///栅格转格网的参数结构体
/// </summary>
struct Raster2GridParams{
    std::string inFileName;
    std::string outFileName;
    DGGSElementType elementType=DGGSElementType::Unknown;
    DGGSGridType gridType=DGGSGridType::Unknown;
    int level=0;

    bool isValid()
    {
        if(inFileName.empty()||outFileName.empty()||elementType==DGGSElementType::Unknown||gridType==DGGSGridType::Unknown)
            return false;
        else
            return true;
    }
};

/// <summary>
/// 格网转栅格的参数结构体
/// </summary>
struct Grid2RasterParams{
    std::string inFileName;
    std::string outFileName;
    DGGSElementType elementType=DGGSElementType::Unknown;
    DGGSGridType gridType=DGGSGridType::Unknown;

    bool isValid()
    {
        if(inFileName.empty()||outFileName.empty()||elementType==DGGSElementType::Unknown||gridType==DGGSGridType::Unknown)
            return false;
        else
            return true;
    }
};

/// <summary>
/// 生成多分辨率格网的参数结构体
/// </summary>
struct FieldPyramidParams{
    std::string inFileName;
    std::string outFileName;
    double tileFileSize=0.0;
    int minLevel=5;
    int maxLevel=-1;

    bool isValid()
    {
        if(inFileName.empty()||outFileName.empty())
            return false;
        else if(tileFileSize==0.0)
            return false;
        else
            return true;
    }
};


/// <summary>
/// 生成全球格网的json文件
/// </summary>
/// <param name="outFileName">输出文件</param>
/// <param name="level">层级</param>
/// <param name="elementType">要素类型</param>
void createGlobalGrid(const char* outFileName,int level,DGGSElementType elementType,DGGSGridType gridType);

/// <summary>
/// 生成局部格网的json文件
/// </summary>
/// <param name="outFileName">输出文件</param>
/// <param name="level">层级</param>
/// <param name="elementType">要素类型</param>
/// <param name="gridType">格网</param>
/// <param name="bound">矩形范围</param>
void createPartialGrid(const char* outFileName,int level,DGGSElementType elementType,DGGSGridType gridType,double*boundBox= nullptr);


/// <summary>
/// OGR文件转DGGS文件
/// </summary>
/// <param name="ogrFileName">源文件</param>
/// <param name="dggsFileName">生成文件</param>
/// <param name="level">层级</param>
/// <param name="gridType">格网类型</param>
/// <param name="elementType">要素类型</param>
bool OGRFile2DGGSFile(const char* ogrFileName,const char* dggsFileName,int level,DGGSGridType gridType,DGGSElementType elementType);

/// <summary>
/// DGGS文件转OGR文件
/// </summary>
/// <param name="dggsFileName">源文件</param>
/// <param name="ogrFileName">生成文件</param>
bool DGGSFile2OGRFile(const char* dggsFileName,const char* ogrFileName);

/// <summary>
/// GDAL的GeoTIFF文件转化为DGGS的GridTIFF文件
/// </summary>
/// <param name="gdalFieldFileName">源文件</param>
/// <param name="dggsFieldFilePath">生成文件</param>
/// <param name="gridType">格网类型</param>
/// <param name="elementType">要素类型</param>
/// <param name="level">层级</param>
void GDALRaster2DGGSField(const char*gdalFieldFileName ,const char *dggsFieldFilePath,DGGSGridType gridType,DGGSElementType elementType,int level=0);

/// <summary>
/// DGGS的GridTIFF文件转化为GDAL的GeoTIFF文件
/// </summary>
/// <param name="dggsFieldFilePath">源文件</param>
/// <param name="gdalFieldFilePath">生成文件</param>
void DGGSField2GDALRaster(const char* dggsFieldFilePath,const char *gdalFieldFilePath);


/// <summary>
/// 生成多分辨率数据
/// </summary>
/// <param name="srcFieldFileName">原始文件</param>
/// <param name="tagFieldFilePath">目标文件夹</param>
/// <param name="tileSileSize">瓦片数据大小</param>
/// <param name="minLevel">分辨率的最小层级,</param>
/// <param name="maxLevel">分辨率的最大层级</param>
void createFieldPyramid(const char* srcFileName, const char * tagFieldFilePath, double tileFileSize, int minLevel=5, int maxLevel=-1);


